<template>
  <div>
 <h1>房号增加</h1>
    <table class="table table-bordered">
      <tbody>
      <tr>
        <td>房号名称</td>
        <td><input type="text" v-model="info.HouseNoName"/></td>
      </tr>
      <tr>
        <td>门店名称</td>
        <td>
          <select v-model="info.Shopid">
            <option value="">请选择</option>
            <option :value="item.id" v-for="item in data1.list">
              {{ item.ShopName }}
            </option>
          </select>
        </td>
      </tr>
      <tr>
        <td>房型名称</td>
        <td>
          <select v-model="info.HouseTypeid">
            <option value="">请选择</option>
            <option :value="item.Id" v-for="item in data2.list">
              {{ item.HouseTypeName }}
            </option>
          </select>
        </td>
      </tr>
      <tr>
        <td>房态</td>
        <td>
          <select v-model="info.HouseState">
            <option value="">请选择</option>
            <option :value="1">空闲</option>
            <option :value="2">已预约</option>
            <option :value="3">已入住</option>
          </select>
        </td>
      </tr>
      <tr>
        <td>房号状态</td>
        <td>
          <input type="radio" name="state" v-model="info.State" :value="1"/>发布
          <input type="radio" name="state" v-model="info.State" :value="0"/>不发布
        </td>
      </tr>
      <tr>
        <td></td>
        <td>
          <input type="button" value="确定" class="btn btn-primary" @click="ok"/>
        </td>
      </tr>
      </tbody>
    </table>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import axios from 'axios';
import moment from 'moment';
import { useRouter, useRoute } from 'vue-router';

const router = useRouter();
const route = useRoute();
const ok = () => {
  //1.有效性判断
  if (info.HouseNoName == '') {
    alert('房型名称不能为空');
    return;
  }
  if (info.ShopId == '') {
    alert('门店名称不能为空');
    return;
  }
  if (info.HouseTypeId == '') {
    alert('房型名称不能为空');
    return;
  }
  if (info.HouseState == '') {
    alert('房态不能为空');
    return;
  }
  //2.发送网络请求
  axios({
    url: '/api/House/HouseNoadd',
    method: 'post',
    data: info,
  })
      .then((res) => {
        console.log(res);
        if (res.data > 0) {
          alert('添加成功');
          router.push('/houseNoList');
        } else if (res.data == -1) {
          alert('房号名称重复');
          return;
        } else {
          alert('添加失败');
          return;
        }
      })
      .catch((err) => {
        console.log(err);
      });
};
let info: any = reactive({
  HouseNoName: '',
  Shopid: '',
  HouseTypeid: '',
  HouseState: 1,
  State: 1,
});
//声明一个变量存储向后端传递的参数
let info1:any=reactive({
  pageIndex:1,
  pageSize:100,
  shopName:"",
  address:""
});

onMounted(() => {
  getShopList();
  getlist();
})

//声明一个变量接受数据
let data1:any =reactive({
  list:[],
  totalCount:0,
  totalPage:0,
})

const  getShopList = () => {
  axios({
    url:'/api/Shop/GetShopList',
    params:info1,
    method:'get'

  }).then((res) => {
    console.log(res)
    data1.list=res.data.list
    data1.totalCount=res.data.totalCount
    data1.totalPage=res.data.totalPage
    //Object.assign(data,res.data);

  })
}
///定义发送
let info2:any=reactive({
  pageindex:1,
  pagesize:100,
  housename:"",
  area1:"",
  area2:"",
})
//定义接受
let data2:any=reactive({
  totalcount:"",
  totalpage:"",
  list:[]
})
const getlist=()=>{
  axios({
    url:"/api/House/GetHouseList",
    method:"get",
    params:info2
  }).then((res)=>{
    console.log(res)
    data2.totalcount = res.data.totalcount
    data2.totalpage = res.data.totalpage
    data2.list = res.data.list
  })
}
</script>

<style >

</style>